package wiki.hitime.stl.daq.bean.base;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author zhangdaoping
 * @create 2019/3/29 下午8:08
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RespDTO<T> {

    /**
     * 状态
     */
    private Integer status;

    /**
     * 消息
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    /**
     * 成功回发
     */
    public static RespDTO success() {
        return RespDTO.success(null);
    }

    /**
     * 成功回发
     */
    public static RespDTO success(Object data) {
        return RespDTO.builder()
                .status(0)
                .msg("")
                .data(data)
                .build();
    }

    /**
     * 失败回发
     */
    public static RespDTO fail(String msg) {
        return RespDTO.builder()
                .status(-1)
                .msg(msg)
                .build();
    }

    /**
     * 失败回发
     */
    public static RespDTO fail(Integer status, String msg) {
        return RespDTO.builder()
                .status(status)
                .msg(msg)
                .build();
    }

    /**
     * 错误回发
     */
    public static RespDTO error(String msg) {
        return RespDTO.builder()
                .status(-99)
                .msg(msg)
                .build();
    }

    /**
     * 错误回发
     */
    public static RespDTO error(Integer status, String msg) {
        return RespDTO.builder()
                .status(status)
                .msg(msg)
                .build();
    }
}
